﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Web;
namespace CatchThatException
{
    class CatchThatException
    {
        public static int LogError(Exception exSend,String logFile)
        {
            try
            {
                StreamWriter objWriter = new StreamWriter(logFile.ToString(),true);
                objWriter.WriteLine("Exception accoured at");
                objWriter.WriteLine(DateTime.Now.ToString());
                objWriter.WriteLine("====================================");
                objWriter.WriteLine("Exception Message:");
                objWriter.WriteLine(exSend.Message.ToString());
                objWriter.WriteLine("====================================");
                objWriter.WriteLine("Exception Source");
                objWriter.WriteLine(exSend.Source.ToString());
                objWriter.WriteLine("====================================");
                objWriter.WriteLine("Exception Stack Trace");
                objWriter.WriteLine(exSend.StackTrace.ToString());
                objWriter.WriteLine("====================================");
                objWriter.WriteLine("====================================");
                objWriter.Dispose();
                objWriter.Close();
                return 0;
            }
            catch (Exception)
            {
                return -1;
            }
        }

    }
}
